const formidable =require('formidable')
const path = require('path')
const upload =(req,resp)=>{
   const form = new formidable.IncomingForm();
   //文件存储位置
   console.log(__dirname)
   form.uploadDir=path.resolve(__dirname,'../public/static/images') 
   //保留后缀名
   form.keepExtensions = true
   //把文件存入uploadDir目录
   form.type = true
    form.parse(req, function(err, fields, files) {
       const imgpath = files.img.path
       const { base }=path.parse(imgpath)
       resp.type('text/plain')
       resp.json({fields: fields, files: files,src:'../static/images/'+ base });
    });
}

module.exports={
   upload
}